package com.java46.struts2.base.util;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java46.struts2.base.entity.TOrderdetailEntity;
import com.java46.struts2.base.exception.BusinessException;

import java.util.*;

/**
 * @ClassName JsonUtils
 * @Description TODO
 * @Author zuxia
 * @Date 2018/7/20 14:42
 * @Vcrsion 1.0
 **/
public class JsonUtils {

    /**
    *@Author xiao
    *@Description //把json字符串解析为对象集合
    *@Date 15:11 2018/7/20
    *@Param [data]
    *@return java.util.List
    */
    public static List getList(String data){
        List list = new ArrayList();
        try {
            JSONArray jsonArray = JSONArray.parseArray(data);
              int size = jsonArray.size();
              for (int i = 0; i < size; i++) {
                  JSONObject jsonObject = jsonArray.getJSONObject(i);
                  TOrderdetailEntity orderdetailEntity=new TOrderdetailEntity();
                  orderdetailEntity.setdId(jsonObject.getInteger("dId"));
                  orderdetailEntity.setCount(jsonObject.getInteger("fCount"));
                  list.add(orderdetailEntity);
              }
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException("jsonz字符串转换出错");
        }
        return list;
    }
}
